<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>验证码</title>
    <style>
        body {
            background: #f5f6fa;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'Segoe UI', Arial, sans-serif;
        }
        #confirm {
            background: #fff;
            padding: 40px 30px 30px 30px;
            border-radius: 16px;
            box-shadow: 0 4px 24px rgba(0,0,0,0.08);
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 24px;
            font-weight: 500;
            letter-spacing: 2px;
        }
        #inputCaptcha {
            height: 36px;
            width: 160px;
            border: 1px solid #dcdcdc;
            border-radius: 6px;
            padding: 0 12px;
            font-size: 16px;
            margin-right: 12px;
            outline: none;
            transition: border 0.2s;
        }
        #inputCaptcha:focus {
            border: 1.5px solid #409eff;
        }
        #verificationCodeImg {
            vertical-align: middle;
            border-radius: 6px;
            box-shadow: 0 2px 8px rgba(64,158,255,0.08);
            margin-bottom: 16px;
            margin-top: 8px;
            border: 1px solid #e0e0e0;
            transition: box-shadow 0.2s;
        }
        #verificationCodeImg:hover {
            box-shadow: 0 4px 16px rgba(64,158,255,0.18);
        }
        #checkCaptcha {
            height: 40px;
            width: 120px;
            background: linear-gradient(90deg, #409eff 0%, #66b1ff 100%);
            color: #fff;
            border: none;
            border-radius: 8px;
            font-size: 18px;
            font-weight: 500;
            margin-top: 18px;
            cursor: pointer;
            box-shadow: 0 2px 8px rgba(64,158,255,0.08);
            transition: background 0.2s, box-shadow 0.2s;
        }
        #checkCaptcha:hover {
            background: linear-gradient(90deg, #66b1ff 0%, #409eff 100%);
            box-shadow: 0 4px 16px rgba(64,158,255,0.18);
        }
        .input-group {
            display: flex;
            align-items: center;
            margin-bottom: 8px;
        }
    </style>
</head>

<body>
    <!-- 验证码输入区域的容器，居中显示，带圆角和阴影 -->
    <div id="confirm">
        <!-- 标题 -->
        <h1>输入验证码</h1>
        <!-- 输入框和验证码图片组合 -->
        <div class="input-group">
            <!-- 用户输入验证码的文本框 -->
            <input type="text" name="inputCaptcha" id="inputCaptcha" placeholder="请输入验证码">
            <!-- 验证码图片，点击可刷新 -->
            <img id="verificationCodeImg" src="/captcha/get" style="cursor: pointer;" title="看不清？换一张" />
        </div>
        <!-- 提交按钮 -->
        <input type="button" value="提交" id="checkCaptcha">
    </div>
    <!-- 引入jQuery库 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
    <script>
        // 点击验证码图片时刷新图片
        $("#verificationCodeImg").click(function(){
            $(this).hide().attr('src', '/captcha/get?dt=' + new Date().getTime()).fadeIn();
        });

        // 点击提交按钮时发送请求到服务端进行校验
        $("#checkCaptcha").click(function () {
            $.ajax({
                type: "POST",
                url: "/captcha/check",
                data: {
                    captcha: $("#inputCaptcha").val()
                },
                success: function (result) {
                    if (result) {
                        // 验证成功，跳转到成功页面
                        window.location.href = "/success.html";
                    } else {
                        // 验证失败，提示用户
                        alert("验证码错误，请重新输入！");
                        $("#inputCaptcha").val(""); // 清空输入框
                        $("#verificationCodeImg").click(); // 刷新验证码图片
                    }
                },
                error: function () {
                    alert("请求失败，请稍后再试！");
                }
            });
        });
    </script>
</body>
</html>